/*
 * Copyright (c) 2019.  鼎捷软件股份有限公司.All rights reserved.
 */

package com.digiwin.dap.middleware.util;

import org.springframework.util.Assert;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 日期格式话
 *
 * @author Seven
 * @date 2019/1/23
 */
public class DateUtil {

    private static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";


    public static LocalDateTime getDateByStr(String dateStr) {
        return getDateByStr(dateStr, YYYY_MM_DD_HH_MM_SS);
    }

    public static LocalDateTime getDateByStr(String dateStr, String formatter) {
        Assert.hasText(formatter, "格式话字符串不能为空");
        if (dateStr == null) {
            return null;
        }
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern(YYYY_MM_DD_HH_MM_SS);
        return LocalDateTime.parse(dateStr, dtf);
    }
}
